
#include <stdio.h>
#include <stdlib.h>
typedef int DataType;

struct node
{
    DataType saleAmount ;//销售数量
    struct node *next;//指向下一产品的指针
} ;


typedef struct node * pNode;

//函数功能： 遍历链表并输出链表中各数据元素的值 
void traverseList_link(pNode pllist) //功能是输出线性表pllist的元素，以空格为分界符；
{
    pNode temp = pllist->next ;
    while(temp != NULL)
    {
        printf("%d ",temp->saleAmount);
        temp = temp->next;
    }
}

//创建一个空的链表 
pNode  createNullList_link(void  )
{
    struct node* temp = (struct node*)malloc(sizeof(struct node)) ;
    temp->next = NULL;
    temp->saleAmount = 0;
    return temp;
}

void insert_link(pNode pllist ,DataType x )
{
    pNode temp =  (struct node*)malloc(sizeof(struct node)) ;
    temp->saleAmount = x ;
    temp->next = NULL;
    pNode p = pllist->next , pre = pllist;
    while(p!=NULL)
    {
        pre = p ;
        p = p->next ;
    }
    pre->next = temp ;
}


void reverseList_link( pNode pllist)
{
    //请在此处填入代码，实现链表逆置功能 
    /********** Begin **********/
    struct node *p,*t;
    p=pllist->next;
    while(p->next) {
        t = p->next;
        p->next = t->next;
        t->next = pllist->next;
        pllist->next = t;
    }

    /********** End **********/
}

int main(void)
{
    pNode pllist = createNullList_link() ;
    int num ;
    DataType data;
    scanf("%d",&num);
    for(int i = 0;i < num; i++)
    {
        scanf("%d",&data);
        insert_link(pllist, data);
    }
    reverseList_link(pllist)	;
    traverseList_link(pllist);
}
 